package screen;

import game.Configurations;
import images.ImageInfo;
import math.Point;
import static org.lwjgl.opengl.GL11.glColor3f;
import org.newdawn.slick.opengl.Texture;

public class ListaImagem extends Lista {

    private Texture textura;
    private ImageInfo[] imgs;
    private Box[] caixas;
    private int w, h;

    public ListaImagem(int x, int y, int w, int h, Texture textura, ImageInfo[] imgs) {
        super(x, y);
        if (this.y == Texto.CENTRALIZADO)
            this.y = (Configurations.SCREEN_HEIGHT - h) / 2;
        if (this.x == Texto.CENTRALIZADO)
            this.x = (Configurations.SCREEN_WIDTH - w) / 2;
        this.w = w;
        this.h = h;

        this.textura = textura;
        this.imgs = imgs;
        this.caixas = new Box[imgs.length];
        for (int i = 0; i < imgs.length; i++)
            this.caixas[i] = new Box(this.x + i * (this.w + 4), this.y - 1, this.w + 2, this.h + 2);
        this.caixas[0].setSelected(true);
    }
    
    public Point getPosition(int pos) {
        return new Point(x + pos * (w + 5) + 5, y + 5);
    }
    
    public int getRealWidth() {
        return w - 10;
    }
    
    public int getRealHeight() {
        return w - 10;
    }

    @Override
    public void desenhar() {
        for (int i = 0; i < imgs.length; i++) {
            glColor3f(255, 255, 255);
            caixas[i].desenhar();
            if (textura != null) {
                glColor3f(255, 255, 255);
                textura.bind();
                imgs[i].draw(x + i * (w + 5) + 5, y + 5, w - 10, h - 10);
            }
        }
    }

    @Override
    public void mover(int dx) {
        this.caixas[selecao].selected = false;
        super.mover(dx);
        this.caixas[selecao].selected = true;
    }

    @Override
    public int getTamanhoMaximo() {
        return imgs.length;
    }
}
